package dk.lector.utils;

import android.content.Context;

public class IconLoader {
	private static final int DEFAULT_ICON = 07;

//	public static int getReference(int documentID, Context context) {
//		int type = DocDBRepository.getDocumentType(context, documentID);
//		return parseType(type, context);
//	}

	public static int parseType(int type, Context context) {
		// TODO package needs to be read according to what environment is
		// running.
		int identifier = context.getResources().getIdentifier(pad(type),
				"drawable", "dk.lector");

//		Log.d("IconLoader", "identifier found for this document/type : "
//				+ identifier + " while serching for : " + pad(type)
//				+ " with input : " + type);

		return (identifier == 0) ? getDefault(context) : identifier;
	}

	public static int getDefault(Context context) {
		return context.getResources().getIdentifier(pad(DEFAULT_ICON),
				"drawable", "dk.lector");
	}

	private static String pad(int type) {
		if (type <= 0 || type > 65)
			return pad(DEFAULT_ICON);
		return (String.valueOf(type).length() < 2 && type <= 9) ? "i0" + type
				: "i" + String.valueOf(type);

	}

}
